package cn.chint.service;

import cn.chint.mapper.UserMapper1;
import cn.chint.model.SysUser;
import cn.chint.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UserService {
    @Autowired
    private UserMapper1 userMapper1;

    public SysUser selectSysUser(String name,String password) {
        SysUser sysUser = userMapper1.selectSysUser(name,password);
        return  sysUser;
    }

    @Transactional
    public void addUser(User user)throws Exception{
        userMapper1.addUser(user.getName(),user.getAge());
    }
    public List<User> selectUser(String name) {
        List<User> ls = userMapper1.selectUser(name);
        return  ls;
    }
    public User selectUser_by_id(Long  id) {
        User u = userMapper1.selectUser_by_id(id);
        return  u;
    }

    @Transactional
    public int updateUser_by_id(Long id,int age)throws Exception{
        int n = userMapper1.updateUser_by_id(id,age);
        return n;
    }

    @Transactional
    public int  deleteUser_by_id(Long id)throws Exception{
       int n  = userMapper1.deleteUser_by_id(id);
       return n;
    }

}
